package com.xdl.flytest.util.runner;

import com.xdl.flytest.util.docker.DockerEnvironmentConfig;
import com.xdl.flytest.util.docker.DockerManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Auther: 80736
 * @Date: 2019/1/31 13:28
 * @Description: 测试集运行器
 */

@Component
public class TestSuitRunner extends BaseRunner {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void run(String containerId) {
        // 创建test project
        DockerManager.createTestProject(containerId, "/home/test");
        // 1.复制本地json文件夹到容器内
        DockerManager.copyLocalFile(containerId, DockerEnvironmentConfig.JSON_FILE_PATH, "/home/test/testcases");
        // 2. 运行测试
        logger.debug("====runing test start====");
        DockerManager.execCmdResult(String.format("docker exec %s hrun %s --report-dir %s", containerId, "/home/test/testcases/", "/home/test/reports"));
        logger.debug("====runing test complete====");
        // 3. 复制测试报告到本地
        DockerManager.copyDockerFile(containerId, "/home/test/reports", DockerEnvironmentConfig.LOCAL_REPORT_SAVED_PATH);

    }

}
